//cookie设置读取和删除
//设置
function setCookie(name, value, day) {
    var Days = day;
    var isObject = Object.prototype.toString.call(value) === "[object String]";
    if (!isObject) {
        value = JSON.stringify(value);
    }
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//读取
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        var cookieValue = unescape(arr[2]);
        try {
            if (JSON.parse(cookieValue)) {
                throw "success";
            } else {
                throw "error";
            }
        }
        catch (err) {
            if (err == "success")
                cookieValue = JSON.parse(cookieValue);
        }
        return cookieValue;
    }
    else {
        return null;
    }
}
//删除
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) {
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
}
